package com.starsea.book.ui.newpage

import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import com.starsea.book.R
import com.starsea.book.base.VMBaseActivity
import com.starsea.book.databinding.ActivityMsgBinding
import com.starsea.book.ui.newpage.adapter.MyPagerAdapter
import com.starsea.book.ui.newpage.viewmodel.MsgViewModel
import com.starsea.book.utils.viewbindingdelegate.viewBinding

/**
 * @author Lee
 * @createTime 2024-01-10 10 GMT+8
 * @desc : 书友圈
 */
class BookCircleActivity : VMBaseActivity<ActivityMsgBinding, MsgViewModel>() {
    override val binding by viewBinding(ActivityMsgBinding::inflate)
    override val viewModel by viewModels<MsgViewModel>()

    val mFragments: MutableList<Fragment> = ArrayList()

    var myPagerAdapter: MyPagerAdapter? = null

    val listTitle: MutableList<String> = ArrayList()

    var index = 0

    override
    fun onActivityCreated(savedInstanceState: Bundle?) {

        setTitle(R.string.title_book_circle)

        listTitle.clear()
        mFragments.clear()
        listTitle.add("关注")
        listTitle.add("书荒广场")
        mFragments.add(
            BookCircleAttentionFragment.newInstance()
        )
        mFragments.add(
            BookCircleGroundFragment.newInstance()
        )
        if (myPagerAdapter == null)
            myPagerAdapter = MyPagerAdapter(supportFragmentManager, mFragments, listTitle)

        binding.vpContent.offscreenPageLimit = listTitle.size
        binding.vpContent.adapter = myPagerAdapter
        binding.stlTab.setViewPager(binding.vpContent)
        binding.vpContent.currentItem = index

    }

    override fun setTitle(resId: Int) {
        super.setTitle(resId)
        binding.titleBar.setTitle(resId)
    }

}